<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            height: 10000px;
            background-color: #ccc;
        }

        #showScroll {
            font-size: 30px;
            position: fixed;
            /* 相对浏览器窗口对位 */
            top: 0;
        }
    </style>
</head>

<body>
    <p id="showScroll">0px</p>

    <script>
        const showScroll = document.querySelector('#showScroll')
        window.addEventListener("scroll", function () {
            showScroll.innerHTML = parseInt(document.documentElement.scrollTop) + 'px'
        })
    </script>
</body>

</html>